<#--  添加在线留言 -->
<@function>
	<#--  返回Map<String,Object>类型 -->
	<#assign returnValue = feedbackRelated_addFeedback_collection>
	<div class="addFeedbackModule" >
	<#--  全局允许提交在线留言 -->
	<#if returnValue['allowFeedback'] == true>
	
		<!-- 令牌标记 -->
		<input type="hidden" id="token" name="token" value="${token}">
       	<div class="title">
       		<span>在线留言</span>
       	</div>
       	
       	<div class="box">
       		<div class="form">
				<div class="form-field" >
	        		<div id="name_field_error" class="form-field-container">
		        		<div class="form-field-text">
		        			<div class="form-field-input-container">
			        			<input id="name" maxLength="30" class="form-field-text-input" type="text" value="" onfocus="inputBoxClickTip(this);" onblur="inputBoxOutTip(this);">
			        			<label class="form-field-label"><span class="required">*</span>称呼</label>
		        			</div>
		        		</div>
	        			<div id="name_prompt_error" class="form-field-prompt-error"></div>
	        		</div>
	        	</div>
	        	<div class="form-field" >
	        		<div id="contact_field_error" class="form-field-container">
		        		<div class="form-field-text">
		        			<div class="form-field-input-container">
			        			<input id="contact" maxLength="30" class="form-field-text-input" type="text" value="" onfocus="inputBoxClickTip(this);" onblur="inputBoxOutTip(this);">
			        			<label class="form-field-label"><span class="required">*</span>邮箱</label>
		        			</div>
		        		</div>
	        			<div id="contact_prompt_error" class="form-field-prompt-error"></div>
	        		</div>
	        	</div>
	        	<div class="form-field" >
	        		<div id="content_field_error" class="form-field-container">
		        		<div class="form-field-radio">
		        			<div class="form-field-radio-container">
		        				<div class="form-field-radio-input">
			        				<textarea id="content" ></textarea>
			        			</div>
			        			<label class="form-field-label form-field-active"><span class="required">*</span>内容</label>
		        			</div>
		        		</div>
	        			<div id="content_prompt_error" class="form-field-prompt-error"></div>
	        		</div>
	        	</div>
	        	<div id="captchaValue_field" class="form-field" <#if returnValue['captchaKey'] == "">	style='display: none;'</#if>>
		        	<div id="captchaValue_field_error" class="form-field-container">
		        		<div class="form-field-text">
				        	<div class="form-field-input-container">
					        	<input type="hidden" id="captchaKey" name="captchaKey" value="${(returnValue['captchaKey'])!}">
					        	<input id="captchaValue" class="form-field-text-input" type="text" maxlength="4" value="" onfocus="inputBoxClickTip(this);" onblur="inputBoxOutTip(this);">
					        	<label class="form-field-label">验证码</label>
							</div>
					        <div class="form-field-image-container">
								<img id="captcha" src="captcha/${(returnValue['captchaKey'])!}.jpg" onClick="replaceCaptcha();" tabindex="4" />
								
					        </div>
					        <div class="form-field-button-container" style="background: #fff;">
					        	<button type="button" class="btn btn-link" tabindex="-1" onClick="replaceCaptcha();">换一幅</button>
					        </div>
					    </div>
					    <div id="captchaValue_prompt_error" class="form-field-prompt-error"></div>
					</div>
	        	</div>
        	</div>
		</div>
		<div id="token_prompt_error" style="color: red;">${(error['token'])!}</div>
       	<div id="feedback_prompt_error" style="color: red;">${(error['feedback'])!}</div>

      		<div class="submitButton-box">
			<a href="javascript:void(0);" onClick="javascript:ajaxSubmit()" tabindex="6">提&nbsp;交</a>
		</div>	
			
		<script language="javascript" type="text/javascript">
			$(".form-field").find(".form-field-input-container").bind("mousedown",function(e) {
				$(this).find(".form-field-text-input").focus();
				
				if($(this).find(".form-field-label").hasClass("form-field-active")){
					return;
				
				}
				$(this).find(".form-field-label").addClass("form-field-active");
			});
			
			$(document).mousedown(function (e) {
		        var target = $(e.target);
		        if (target.closest(".form-field-input-container").length == 0) {
		            $(".form-field-input-container").each(function(){
					    if($(this).find(".form-field-label").hasClass("form-field-active")){
							if($(this).find('input[type="text"]').val() == "" || $(this).find('input[type="password"]').val() == ""){
								$(this).find(".form-field-label").removeClass("form-field-active");
							}
							
						}
					});
		        }
		    });
		    //文本框含有默认值时字段名称缩小
			$(document).ready(function(){
				$(".form-field-input-container").each(function(){
				    if(!$(this).find(".form-field-label").hasClass("form-field-active")){
						if(($(this).find('input[type="text"]').val() != undefined && $(this).find('input[type="text"]').val() != '') 
							|| $(this).find('input[type="password"]').val() != undefined && $(this).find('input[type="password"]').val() != ''){
							$(this).find(".form-field-label").addClass("form-field-active");
						}
						
					}
				});
			});
			
			
			//监听Tab键
		    $(document).on('keyup',function (e) {
			    if(e.keyCode == 9){
			    	var input = $(this).find('input:focus');
			    	if (input.length) {
				    	if(!input.parent().parent().find(".form-field-label").hasClass("form-field-active")){
							input.parent().parent().find(".form-field-label").addClass("form-field-active");
						}
				    }
				}
			});
		    //解决提交按钮的click和blur事件冲突
			$(document).ready(function(){
				$("input[type='button']").mousedown(function(e){
			    	e.preventDefault();
				});
				$("a[href='javascript:void(0);']").mousedown(function(e){
			    	e.preventDefault();
				});
				
			});
		
		</script>
		
		<script language="javascript" type="text/javascript">
			//点击输入框提示
			function inputBoxClickTip(obj){
			
			
			}
			//离开输入框提示
			function inputBoxOutTip(obj){
				verification(obj.id);
			}
			//验证参数
			function verification(field){
				$("#"+field+"_prompt_error").hide();
				$("#"+field+"_field_error").removeClass("form-field-error");
				
				if(field == "captchaValue"){//验证码
					if(!$("#captchaValue_field").is(":hidden")){//如果验证码框显示
						var captchaKey = $("#captchaKey").val().trim();
						var captchaValue = $("#"+field).val().trim();
						if(captchaValue == ""){
							$("#"+field+"_prompt_error").html("验证码不能为空");
							$("#"+field+"_prompt_error").show();
							$("#"+field+"_field_error").addClass("form-field-error");
							return false;
						}
						
						get_request(function(value){
			            	if(value == "false"){
			            		$("#"+field+"_prompt_error").html("验证码错误");
								$("#"+field+"_prompt_error").show();
								$("#"+field+"_field_error").addClass("form-field-error");
			            	}
			            },
					 		"userVerification?captchaKey="+captchaKey+"&captchaValue="+captchaValue+"&timestamp=" + new Date().getTime(), true);
			            	
					}
				}
				return true;
			}
			//更换验证码
			function replaceCaptcha(){
				var captchaKey = document.getElementById("captchaKey").value;
				document.getElementById("captcha").src = "captcha/"+captchaKey+".jpg?" + Math.random(); 
			}
			
			//组装参数
			function getParameter(){
				var parameter = "";
				
				//令牌标记
				var token = $("#token").val();
				parameter += "&token="+token;
				
				//验证码Key
				parameter += "&captchaKey="+encodeURIComponent($("#captchaKey").val());
				
				//验证码值
				parameter += "&captchaValue="+encodeURIComponent($("#captchaValue").val());

				//称呼
				parameter += "&name="+encodeURIComponent($("#name").val().trim());
				//邮箱	
				parameter += "&contact="+encodeURIComponent($("#contact").val().trim());
				//内容
				parameter += "&content="+encodeURIComponent($("#content").val().trim());
				
				return parameter;
			}
			//ajax提交
			function ajaxSubmit(){
				
				var parameter = getParameter();
				if(parameter.indexOf("&") == 0){
					parameter = parameter.substring(1,parameter.length);
				}
				post_request(function(value){
					if(value != ""){
						var returnValue = JSON.parse(value);//JSON转为对象
						for(var key in returnValue){
							if(key == "success"){	
								var success = returnValue[key];	
								if(success == "true"){
									layer.msg('留言成功，3秒后自动跳转', {
										time: 3000 //3秒关闭（如果不配置，默认是3秒）
										},function(){//关闭后的操作
											//跳转到首页
											window.location.href = getBasePath()+"index";
										}
									);
									
								}
							}else if(key == "error"){
								var errorValue = returnValue[key];
								for(var error in errorValue){
									if(error != ""){
										$("#"+error+"_prompt_error").html(errorValue[error]);
										$("#"+error+"_prompt_error").show();
										$("#"+error+"_field_error").addClass("form-field-error");	
									}
								}
							}else if(key == "captchaKey"){//显示验证码	
								var captchaKey = returnValue[key];
								if(captchaKey != ""){
									$("#captchaValue_field").show();
									//设置验证码Key
									$("#captchaKey").val(captchaKey);
									
									//设置验证码图片
									replaceCaptcha();
								}
							}
						}
						
					}	
				},
					"feedback/control/add?timestamp=" + new Date().getTime(), true,parameter);
			}
		</script>	
	<#else>
		<div class="addFeedbackModulePrompt">
			<div class="disableForm-wrap">
				<div class="respond">
					<p >在线留言已关闭</p>
				</div>
			</div>
		</div>
	</#if>
	</div>
</@function>
